<template>
  <el-form ref="formRef" :model="form" label-width="120px" size="default">
    <el-form-item>
      <h2>
        <el-link type="warning">根据试管号阴性转阳性</el-link>
      </h2>
    </el-form-item>
    <el-form-item label="试管号：">
      <el-input v-model="form.tubeCode" clearable class="input-width"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">生成脚本</el-button>
      <el-button type="default" @click="exportFile">导出文件</el-button>
    </el-form-item>
    <el-form-item label="脚本：">
      <el-input autosize type="textarea" v-model="form.scriptString" readonly></el-input>
    </el-form-item>
  </el-form>
</template>

<script setup>
import { reactive } from "vue";
import saveAs from "./js/FileSaver";
// do not use same name with ref
const form = reactive({
  // 试管号
  tubeCode: "",
  // 脚本
  scriptString: ""
});

const exportFile = () => {
  let str = new Blob([form.scriptString], {
    type: "text/plain;charset=utf-8"
  });
  saveAs(str, `试管${form.tubeCode}阴改阳.txt`);
};

const onSubmit = () => {
  let code = form.tubeCode;
  form.scriptString = `环境：太极政务云
数据库地址：192.159.107.33:2000
数据库名：nat_admin

先备份：（请将备份的数据写在jira的备注里，如果数据多，可以生成txt文件上传到jira里）
var c = db.nat_tube.find({"tube_code":{"$in":["${code}"]}})
d = []
while(c.hasNext()) {
d.push(c.next())
}
printjson(d)

var c = db.nat_appo_check.find({"tube_code":{"$in":["${code}"]}})
d = []
while(c.hasNext()) {
d.push(c.next())
}
printjson(d)

var c = db.nat_appo_check_relation.find({"tube_code":{"$in":["${code}"]}})
d = []
while(c.hasNext()) {
d.push(c.next())
}
printjson(d)

再修改：
db.nat_tube.update({$and:[{"tube_code":{"$in":["${code}"]}}]}, {$set:{"check_result":NumberInt(1)}}, false, true);
db.nat_appo_check.update({$and:[{"tube_code":{"$in":["${code}"]}}]}, {$set:{"check_result":NumberInt(1)}}, false, true);
db.nat_appo_check_relation.update({$and:[{"tube_code":{"$in":["${code}"]}}]}, {$set:{"check_result":NumberInt(1)}}, false, true);
db.nat_appo_check.update({$and:[{"tube_code":{"$in":["${code}"]}}]}, {$unset:{"report_path":1,"dongAoReportPath":1,"check_result_sync_flag":1}}, false, true);`;
};
</script>

<style>
.input-width {
  width: 500px;
}
</style>
